if (!t3_ng_app_index_config_done) { t3_ng_app_index.config(function($mdThemingProvider, $mdIconProvider){ // $mdIconProvider // .defaultIconSet("./assets/svg/avatars.svg" , 128) // .icon("menu" , "./assets/svg/menu.svg" , 24) // .icon("share" , "./assets/svg/share.svg" , 24) // .icon("google_plus", "./assets/svg/google_plus.svg" , 512) // .icon("hangouts" , "./assets/svg/hangouts.svg" , 512) // .icon("twitter" , "./assets/svg/twitter.svg" , 512) // .icon("phone" , "./assets/svg/phone.svg" , 512); //here you change placeholder/foreground color. $mdThemingProvider.theme('default').foregroundPalette[3] = "rgba(0,0,0,0.8)"; $mdThemingProvider.theme('success-toast'); $mdThemingProvider.theme('warning-toast'); $mdThemingProvider.theme('error-toast'); // red, pink, purple, deep-purple, // indigo, blue, light-blue, cyan, teal, // green, light-green, lime, yellow, amber, // orange, deep-orange, brown, grey, blue-grey $mdThemingProvider.theme('default') .primaryPalette('indigo') .accentPalette('pink') .warnPalette('red'); }); t3_ng_app_index.config(function($locationProvider){ $locationProvider.html5Mode(true).hashPrefix('*'); }); t3_ng_app_index.config(function($mdDateLocaleProvider) { // Localization. $mdDateLocaleProvider.months = T3_NG_CALENDAR_month; $mdDateLocaleProvider.shortMonths = T3_NG_CALENDAR_month_short; $mdDateLocaleProvider.days = T3_NG_CALENDAR_days_of_week; $mdDateLocaleProvider.shortDays = T3_NG_CALENDAR_days_of_week_short; $mdDateLocaleProvider.firstDayOfWeek = T3_NG_CALENDAR_first_day_of_week; // Optional. //$mdDateLocaleProvider.dates = [1, 2, 3, 4, 5, 6, ...]; // Example uses moment.js to parse and format dates. var locale = window.navigator.userLanguage || window.navigator.language; moment.locale(locale); $mdDateLocaleProvider.parseDate = function(dateString) { var m = moment(dateString, 'L', true); var n = m.isValid() ? m.toDate() : new Date(NaN); return n; }; $mdDateLocaleProvider.formatDate = function(date) { var m = moment(date).format('L'); return m; }; $mdDateLocaleProvider.monthHeaderFormatter = function(date) { return $mdDateLocaleProvider.shortMonths[date.getMonth()] + ' ' + date.getFullYear(); }; // In addition to date display, date components also need localized messages // for aria-labels for screen-reader users. $mdDateLocaleProvider.weekNumberFormatter = function(weekNumber) { return T3_NG_CALENDAR_week_label + weekNumber; }; $mdDateLocaleProvider.msgCalendar = T3_NG_CALENDAR_calendar_label; $mdDateLocaleProvider.msgOpenCalendar = T3_NG_CALENDAR_open_calendar_label }); // Twig workaround t3_ng_app_index.config(function($interpolateProvider){ $interpolateProvider.startSymbol('{[{').endSymbol('}]}'); }); // t3_ng_app_index.directive('dynController', ['$compile', '$parse',function($compile, $parse) { // return { // restrict: 'A', // terminal: true, // priority: 100000, // link: function(scope, elem, attrs) { // // Parse the scope variable // //t3_ng_ctr_{[{ 'layout.NgSelectEntityName |lowercase' }]}_select // var name = 't3_ng_ctr_' + ($parse(elem.attr('dyn-controller'))(scope)).toLowerCase() + '_select'; // elem.removeAttr('dyn-controller'); // elem.attr('ng-controller', name); // // Compile the element with the ng-controller attribute // $compile(elem)(scope); // } // }; // }]); t3_ng_app_index.directive('ngDynamicController', ['$compile', '$parse', function($compile, $parse) { return { restrict: 'A', terminal: true, priority: 100000, link: function($scope, $element) { var attribute = $element.attr('ng-dynamic-controller'); var name = $parse(attribute)($scope); $element.removeAttr('ng-dynamic-controller'); $element.attr('ng-controller', name.replace('.','_')); $compile($element)($scope); } }; }]); // t3_ng_app_index.directive('ngDynamicName', function($compile, $parse) { // return { // restrict: 'A', // terminal: true, // priority: 100000, // link: function($scope, $element) { // var attribute = $element.attr('ng-dynamic-name'); // var name = $parse(attribute)($scope); // // $interpolate() will support things like 'skill'+skill.id where parse will not // $element.removeAttr('ng-dynamic-name'); // $element.attr('name', name); // $compile($element)($scope); // } // }; // }); t3_ng_app_index.directive('ngDynamicSrc', ['$compile', '$parse',function($compile, $parse) { return { restrict: 'A', terminal: true, priority: 100000, link: function(scope, elem) { var name = $parse(elem.attr('ng-dynamic-src'))(scope); elem.removeAttr('ng-dynamic-src'); elem.attr('src', name); $compile(elem)(scope); } }; }]); t3_ng_app_index.directive('ngDynamicRepeat', ['$compile', '$parse',function($compile, $parse) { return { restrict: 'A', terminal: true, priority: 100000, link: function(scope, elem) { var name = $parse(elem.attr('ng-dynamic-repeat'))(scope); elem.removeAttr('ng-dynamic-repeat'); elem.attr('ng-repeat', name); $compile(elem)(scope); } }; }]); t3_ng_app_index.directive('file', function () { return { scope: { file: '=' }, link: function (scope, el, attrs) { el.bind('change', function (event) { var file = event.target.files[0]; scope.file = file ? file : undefined; scope.$apply(); }); } }; }); t3_ng_app_index.directive('t3TrafficLight', function() { return { restrict: 'AE', //attribute or element scope: { status: '=', alt: '=', }, link: function(scope, element, attrs) { //attrs.$observe('status', function(value) { scope.$watch('status', function(value) { // TODO observe scope.status switch(scope.status) { case "off": // dark green { element.css("background-color", "#006400"); return ' ' + scope.alt + ''; break; } case "on": // green { element.css("background-color", "#00ff00"); return ' ' + scope.alt + ''; break; } case "warning": // yellow { element.css("background-color", "#ffff00"); return ' ' + scope.alt + ''; break; } case "alarm": // red { element.css("background-color", "#ff0000"); return ' ' + scope.alt + ''; break; } default: // gray { element.css("background-color", "#646464"); return ' ' + scope.alt + ''; } } }); }, template: function(element, attrs) { element.css("border-style", "outset"); element.css("border-radius", "25px"); element.css("padding-left", "1px"); return ' '; } } }); t3_ng_app_index.directive('mdCurrency', [ function() { return { require: '?ngModel', template: '', scope: { ngReadonly: "=ngReadonly", //currencySymbol: "@currencySymbol", //decimalDigits: "@decimalDigits" }, link: function(scope, element, attrs, ngModel, $parse) { if (!ngModel) return; if (attrs.name) scope.name = attrs.name; if (attrs.class) scope.class = attrs.class; scope.currencySymbol = attrs.currencySymbol != undefined ? attrs.currencySymbol : ""; scope.decimalDigits = attrs.decimalDigits != undefined ? attrs.decimalDigits : 2; scope.decimalSeparator = attrs.decimalSeparator != undefined ? attrs.decimalSeparator : ","; scope.thousandSeparator = attrs.thousandSeparator != undefined ? attrs.thousandSeparator : "."; scope.formatMoney = function(n, c, d, t, b) { c = isNaN(c = Math.abs(c)) ? scope.decimalDigits ? scope.decimalDigits : 2 : c; d = d == undefined ? scope.decimalSeparator : d; t = t == undefined ? scope.thousandSeparator : t; b = b == undefined ? scope.currencySymbol ? scope.currencySymbol : '' : b; var s = n < 0 ? "-" : "", i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))); j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "") + " " + b; }; scope.isNumeric = function(n) { return !isNaN(parseFloat(n)) && isFinite(n); } if (attrs.placeholder) scope.placeholder = attrs.placeholder; else scope.placeholder = scope.formatMoney(0); // Model to user input ngModel.$formatters.push(function(modelValue) { var v = modelValue || 0; return scope.formatMoney(v); }); // User input to model ngModel.$parsers.push(function(viewValue) { var v = viewValue || 0; if (!scope.isNumeric(v)) { v = v.replace(scope.thousandSeparator, ''); v = v.replace(scope.decimalSeparator, '.'); v = parseFloat(v); } scope.value = v; return scope.value; }); scope.$watch('value', function() { ngModel.$setViewValue(scope.value); }); scope.onChange = function(){ ngModel.$setViewValue(scope.value); }; ngModel.$render = function() { if (!ngModel.$viewValue) ngModel.$viewValue = 0; scope.value = ngModel.$viewValue; }; scope.onBlur = function(){ var v = scope.formatMoney(scope.value); ngModel.$setViewValue(v); ngModel.$render(); }; scope.onFocus = function(){ var v = scope.value || 0; if (!scope.isNumeric(v)) { v = v.replace(scope.thousandSeparator, ''); v = v.replace(scope.decimalSeparator, '.'); v = parseFloat(v); } scope.value = v; return scope.value; }; } }; }]); t3_ng_app_index.directive('mdWorkinghoursDuration', [ function() { return { require: '?ngModel', template: '', scope: { ngReadonly: "=ngReadonly" }, link: function(scope, element, attrs, ngModel) { if (!ngModel) return; if (attrs.name) scope.name = attrs.name; if (attrs.placeholder) scope.placeholder = attrs.placeholder; else scope.placeholder = 'hh:mm:ss'; if (attrs.class) scope.class = attrs.class; ngModel.$formatters.push(function(modelValue) { if (modelValue === undefined || modelValue == '') return null; var m = moment.duration(modelValue); var s = scope.toString(m); return s; }); ngModel.$parsers.push(function(modelValue) { if (modelValue === undefined || modelValue == '') return null; var m = moment.duration(modelValue); return m; }); scope.toString = function(val) { if (!val) return ''; var m = moment.duration(val); var asHours = m.asHours(); if (asHours < 0) { s = '- '; asHours = asHours * -1; } var hours = Math.floor(asHours); var minutes = m.minutes(); var seconds = m.seconds(); var milliseconds = m.milliseconds(); var s = ''; if (hours > 0) s += hours + 'h '; if (minutes > 0) s += minutes + 'min '; if (seconds > 0) s += seconds + 's '; if (milliseconds > 0) s += milliseconds + 'ms '; if (s == '') return "0s"; else return s; } scope.isNumeric = function(n) { return !isNaN(parseFloat(n)) && isFinite(n); } scope.toEditString = function(val) { var m = moment.duration(val); var hours = Math.floor(m.asHours()); var minutes = padding2(m.minutes()); var seconds = padding2(m.seconds()); var milliseconds = padding3(m.milliseconds()); var s = hours + ':' + minutes + ':' + seconds; if (milliseconds > 0) s += '.' + milliseconds; return s; } scope.onBlur = function(){ if (!scope.value || scope.value == '') { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var m = moment.duration(scope.value); if (scope.isNumeric(scope.value)) { var floatValue = parseFloat(scope.value); m = moment.duration(Math.floor(floatValue * 1000)); } var s = scope.toString(m); scope.value = s; ngModel.$setViewValue(m); }; scope.onFocus = function(){ if (!ngModel.$viewValue) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } // Parse view value var m = moment.duration(ngModel.$viewValue); // No luck, try to parse model value if (m.asMilliseconds() <= 0) m = moment.duration(ngModel.$modelValue); var s = scope.toEditString(m); scope.value = s; ngModel.$setViewValue(m); }; scope.onChange = function(){ var m = moment.duration(scope.value); var s = scope.toEditString(m); ngModel.$setViewValue(m); }; ngModel.$render = function(){ if (!ngModel.$modelValue || ngModel.$modelValue == '') { scope.value = null; ngModel.$setViewValue(null); return; } var m = moment.duration(ngModel.$modelValue); var s = scope.toString(m); ngModel.$setViewValue(s); scope.value = s; }; } }; }]); t3_ng_app_index.directive('mdDate', [ function() { return { require: '?ngModel', template: '', scope: { ngReadonly: "=ngReadonly" }, link: function(scope, element, attrs, ngModel) { var locale = window.navigator.userLanguage || window.navigator.language; moment.locale(locale); if (!ngModel) return; if (attrs.name) scope.name = attrs.name; if (attrs.placeholder) scope.placeholder = attrs.placeholder; else scope.placeholder = ''; // attrs.$observe('ngReadonly', function(newValue) { // scope.ngReadonly = scope.$eval(newValue); // }); if (attrs.class) scope.class = attrs.class; ngModel.$formatters.push(function(modelValue) { if (modelValue === undefined || modelValue == '') return null; var m = moment(modelValue); var s = scope.toString(m); return s; }); ngModel.$parsers.push(function(modelValue) { if (modelValue === undefined || modelValue == '') return null; var m = moment(modelValue); return m; }); scope.toString = function(val) { if (!val) return ''; var m = moment(val); if (!m.isValid()) return ''; return m.format('ll'); } scope.isNumeric = function(n) { return !isNaN(parseFloat(n)) && isFinite(n); } scope.toEditString = function(val) { if (!val) return ''; var m = moment(val); if (!m.isValid()) return ''; return m.format('L'); } scope.onBlur = function(){ if (!scope.value || scope.value == '') { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var m = moment(scope.value, 'L', locale); if (!m.isValid()) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var s = scope.toString(m); scope.value = s; ngModel.$setViewValue(m); }; scope.onFocus = function(){ if (!ngModel.$viewValue) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } // Parse view value var m = moment(ngModel.$viewValue, "LL"); //moment(ngModel.$viewValue); if (!m.isValid()) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var s = scope.toEditString(m); scope.value = s; ngModel.$setViewValue(m); }; scope.onChange = function(){ var m = moment(scope.value); var s = scope.toEditString(m); ngModel.$setViewValue(m); }; ngModel.$render = function(){ if (!ngModel.$modelValue || ngModel.$modelValue == '') { scope.value = null; ngModel.$setViewValue(null); return; } var m = moment(ngModel.$modelValue); if (!m.isValid()) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var s = scope.toString(m); ngModel.$setViewValue(s); scope.value = s; }; } }; }]); t3_ng_app_index.directive('mdTime', [ function() { return { require: '?ngModel', template: '', scope: { ngReadonly: "=ngReadonly" }, link: function(scope, element, attrs, ngModel) { // Keep moment untouched //var locale = window.navigator.userLanguage || window.navigator.language; //moment.locale(locale); if (!ngModel) return; if (attrs.name) scope.name = attrs.name; if (attrs.placeholder) scope.placeholder = attrs.placeholder; else scope.placeholder = ''; if (attrs.class) scope.class = attrs.class; scope.patt = new RegExp("^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$"); scope.validateTimeString = function(timeString) { return (scope.patt.test(timeString)) } scope.normalizeTimeString = function(timeString) { if (!timeString || !scope.validateTimeString(timeString)) return null; var arr = timeString.split(':') hh = ('00' + arr[0]).slice(-2); mm = ('00' + arr[1]).slice(-2); return hh + ":" + mm; } ngModel.$formatters.push(function(modelValue) { if (!modelValue || modelValue == '' || !modelValue._isAMomentObject) return null; var s = scope.toString(modelValue); return s; }); ngModel.$parsers.push(function(modelValue) { if (!modelValue || modelValue == '') return null; if (modelValue._isAMomentObject) return modelValue; if (scope.patt.test(modelValue)) var m = moment.utc('1900-01-01T' + modelValue + 'Z'); return m; }); scope.toString = function(val) { if (!val) return ''; var m = moment(val); if (!m.isValid()) return ''; return m.format('HH:mm'); } scope.isNumeric = function(n) { return !isNaN(parseFloat(n)) && isFinite(n); } scope.toEditString = function(val) { if (!val) return ''; var m = moment(val); if (!m.isValid()) return ''; return m.format('HH:mm'); } scope.onBlur = function(){ if (!scope.patt.test(scope.value)) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } if (!scope.validateTimeString(scope.value)) return; var timeString = scope.normalizeTimeString(scope.value); var m = moment.utc('1900-01-01T' + timeString + 'Z'); var s = scope.toString(m); scope.value = s; //ngModel.$setViewValue(m); ngModel.$setViewValue(s); }; scope.onFocus = function(){ if (!ngModel.$viewValue) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } // Parse view value var m = moment(ngModel.$viewValue, 'HH:mm'); if (!m.isValid()) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var s = scope.toEditString(m); scope.value = s; ngModel.$setViewValue(m); }; scope.onChange = function(){ if (!scope.patt.test(scope.value)) return; if (!scope.validateTimeString(scope.value)) return; var timeString = scope.normalizeTimeString(scope.value); var m = moment.utc('1900-01-01T' + timeString + 'Z'); //var m = moment(scope.value); var s = scope.toEditString(m); ngModel.$setViewValue(m); }; ngModel.$render = function(){ if (!ngModel.$modelValue || ngModel.$modelValue == '') { scope.value = null; ngModel.$setViewValue(null); return; } var m = moment.utc(ngModel.$modelValue); if (!m.isValid()) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var s = scope.toString(m); ngModel.$setViewValue(s); scope.value = s; }; } }; }]); t3_ng_app_index.directive('mdDateTime', [ function() { return { require: '?ngModel', template: '', scope: { ngReadonly: "=ngReadonly" }, link: function(scope, element, attrs, ngModel) { var locale = window.navigator.userLanguage || window.navigator.language; moment.locale(locale); if (!ngModel) return; if (attrs.name) scope.name = attrs.name; if (attrs.placeholder) scope.placeholder = attrs.placeholder; else scope.placeholder = ''; // attrs.$observe('ngReadonly', function(newValue) { // scope.ngReadonly = scope.$eval(newValue); // }); if (attrs.class) scope.class = attrs.class; ngModel.$formatters.push(function(modelValue) { if (modelValue === undefined || modelValue == '') return null; var m = moment(modelValue); var s = scope.toString(m); return s; }); ngModel.$parsers.push(function(modelValue) { if (modelValue === undefined || modelValue == '') return null; var m = moment(modelValue, "DD/MM/YYYY HH:mm") //moment(modelValue); return m; }); scope.toString = function(val) { if (!val) return ''; var m = moment(val); if (!m.isValid()) return ''; return m.format('llll'); } scope.isNumeric = function(n) { return !isNaN(parseFloat(n)) && isFinite(n); } scope.toEditString = function(val) { if (!val) return ''; var m = moment(val); if (!m.isValid()) return ''; return m.format('L') + ' ' + m.format('LT'); } scope.onBlur = function(){ if (!scope.value || scope.value == '') { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var m = moment(scope.value, "DD/MM/YYYY HH:mm"); if (!m.isValid()) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var s = scope.toString(m); scope.value = s; ngModel.$setViewValue(m); }; scope.onFocus = function(){ if (!ngModel.$viewValue) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } // Parse view value var m = moment(ngModel.$viewValue, "llll"); //moment(ngModel.$viewValue); if (!m.isValid()) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var s = scope.toEditString(m); scope.value = s; ngModel.$setViewValue(m); }; scope.onChange = function(){ var m = moment(scope.value); var s = scope.toEditString(m); ngModel.$setViewValue(m); }; ngModel.$render = function(){ if (!ngModel.$modelValue || ngModel.$modelValue == '') { scope.value = null; ngModel.$setViewValue(null); return; } var m = moment(ngModel.$modelValue); if (!m.isValid()) { scope.value = undefined; ngModel.$setViewValue(undefined); return; } var s = scope.toString(m); ngModel.$setViewValue(s); scope.value = s; }; } }; }]); t3_ng_app_index.directive('mdRecurrence', [ function() { return { require: '?ngModel', template: '' + '' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' {[{ t.Name }]}' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' {[{ wd.Name }]}' + ' ' + ' ' + ' ' + ' ' + ' ' + ' {[{ wd.Name }]}' + ' ' + ' ' + ' ' + ' ' + ' ' + ' {[{ wd.Name }]}' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '

{[{ tostring() }]}

' + '
', scope: { ngReadonly: "=ngReadonly", startDate: "=recurrenceStartDate", endDate: "=recurrenceEndDate", length: "=recurrenceLength" }, link: function(scope, element, attrs, ngModel) { if (ngModel) scope.ngModel = ngModel; else return; if (attrs.name) scope.name = attrs.name; // type - the type of repetition: 'day','week','month','year'. // count - the interval between events in the "type" units. // day and count2 - define a day of a month ( first Monday, third Friday, etc ). // days - // weekDays - a comma-separated list of affected week days. // extra - extra info that can be used to change the presentation of recurring details. // "day_3___" - each three days // "month _2___" - each two months // "month_1_1_2_" - second Monday of each month // "week_2___1,5" - Monday and Friday of each second week // "input#extra" scope.clear = function() { scope.input = null; scope.extra = null; // type scope.typeSrc = [ { Name: 'Nessuna', Value: null, MaxCount: 30, Disabled: false }, { Name: 'Giorni', Value: 'day', MaxCount: 30, Disabled: false }, { Name: 'Settim.', Value: 'week', MaxCount: 54, Disabled: false }, { Name: 'Mesi', Value: 'month', MaxCount: 12, Disabled: false }, { Name: 'Anni', Value: 'year', MaxCount: 100, Disabled: false }, { Name: 'Eliminato', Value: 'none', MaxCount: 30, Disabled: true }, { Name: 'Variazione', Value: '', MaxCount: 30, Disabled: true }, ]; scope.type = scope.typeSrc[0]; // count scope.count = null; // dayAndCount2 scope.dayAndCount2Src = [ { Name: '-', Value: null }, { Name: 'Dom', Value: 0 }, { Name: 'Lun', Value: 1 }, { Name: 'Mar', Value: 2 }, { Name: 'Mer', Value: 3 }, { Name: 'Gio', Value: 4 }, { Name: 'Ven', Value: 5 }, { Name: 'Sab', Value: 6 }, ]; scope.dayAndCount2 = scope.dayAndCount2Src[0]; // dayAndCount2Month scope.dayAndCount2MonthSrc = [ { Name: '-', Value: null }, { Name: 'Gen', Value: 0 }, // momentjs style { Name: 'Feb', Value: 1 }, { Name: 'Mar', Value: 2 }, { Name: 'Apr', Value: 3 }, { Name: 'Mag', Value: 4 }, { Name: 'Giu', Value: 5 }, { Name: 'Lug', Value: 6 }, { Name: 'Ago', Value: 7 }, { Name: 'Set', Value: 8 }, { Name: 'Ott', Value: 9 }, { Name: 'Nov', Value: 10 }, { Name: 'Dic', Value: 11 }, ]; scope.dayAndCount2Month = scope.dayAndCount2MonthSrc[0]; // days scope.days = null; // weekDays scope.weekDaysSrc = [ { Name: 'Dom', Value: 0 }, { Name: 'Lun', Value: 1 }, { Name: 'Mar', Value: 2 }, { Name: 'Mer', Value: 3 }, { Name: 'Gio', Value: 4 }, { Name: 'Ven', Value: 5 }, { Name: 'Sab', Value: 6 }, ]; scope.weekDays = []; } // Prepare vars on init scope.clear(); scope.fromString = function(value) { scope.input = value; if (scope.input && scope.input.indexOf('#') > -1) { var tokens0 = scope.input.split('#', 2); scope.input = tokens0[0] scope.extra = tokens0[1]; } if (scope.input == 'none') { scope.type = scope.typeSrc[5]; return; } if (scope.input == '') { scope.type = scope.typeSrc[6]; return; } if (!scope.input) { scope.type = scope.typeSrc[0]; return; } var tokens = scope.input.split('_', 5); if (tokens.length >= 1) { //scope.type = tokens[0]; // { Name: 'Nessuna', Value: null, MaxCount: 30 }, // { Name: 'Giorni', Value: 'day', MaxCount: 30 }, // { Name: 'Settim.', Value: 'week', MaxCount: 54 }, // { Name: 'Mesi', Value: 'month', MaxCount: 12 }, // { Name: 'Anni', Value: 'year', MaxCount: 100 }, switch (tokens[0]) { case "day": scope.type = scope.typeSrc[1]; break; case "week": scope.type = scope.typeSrc[2]; break; case "month": scope.type = scope.typeSrc[3]; break; case "year": scope.type = scope.typeSrc[4]; if (scope.startDate != null && moment(scope.startDate).isValid()) scope.dayAndCount2Month = scope.dayAndCount2MonthSrc[moment(scope.startDate).month()+1]; else scope.dayAndCount2Month = scope.dayAndCount2MonthSrc[0]; break; default: scope.type = scope.typeSrc[0]; break; } } if (tokens.length >= 2 && tokens[1] != '') scope.count = Number(tokens[1]); if (tokens.length >= 3 && tokens[2] != '') { var val = Number(tokens[2]); if (val >= 0 && val <= 6) scope.dayAndCount2 = scope.dayAndCount2Src[val+1]; else scope.dayAndCount2 = scope.dayAndCount2Src[0]; } else scope.dayAndCount2 = scope.dayAndCount2Src[0]; if (tokens.length >= 4 && tokens[3] != '') scope.days = Number(tokens[3]); if (tokens.length >= 5) { if (tokens[4].indexOf(',') > -1) { var tokens1 = tokens[4].split(',', 7); for (var i = 0; i < tokens1.length; i++) { if (tokens1[i] && tokens1[i] != '') { var val = Number(tokens1[i]); if (val >= 0 && val <= 6) scope.weekDays.push(scope.weekDaysSrc[val]); } } } else { if (tokens[4] && tokens[4] != '') { var val = Number(tokens[4]); if (val >= 0 && val <= 6) scope.weekDays.push(scope.weekDaysSrc[val]); } } } if (!scope.startDate) scope.startDate = moment(); if (!scope.endDate) scope.endDate = moment(scope.startDate).add(1, 'hours'); if (!scope.length && scope.type && scope.type.Value) { try { scope.length = moment(scope.endDate).diff(moment(scope.startDate)).asSeconds(); } catch(err) { scope.length = 3600; } } if (scope.length) scope.duration = moment.duration(scope.length, "seconds"); }; scope.skipChangeEvent = false; scope.$watch(attrs['ngModel'], function() { if (!scope.skipChangeEvent) scope.fromString(ngModel.$modelValue); scope.skipChangeEvent = false; }); scope.toString = function() { var str = null; if (scope.type && scope.type.Value) { if (scope.type == 'none') { scope.type = scope.typeSrc[5]; return; } if (scope.type == '') { scope.type = scope.typeSrc[6]; return; } if (!scope.length && scope.type && scope.type.Value) { try { scope.length = moment(scope.endDate).diff(moment(scope.startDate)).asSeconds(); } catch(err) { scope.length = 3600; } } if (scope.length) scope.duration = moment.duration(scope.length, "seconds"); // type str = scope.type.Value; str += '_'; // type_count if (!scope.count) scope.count = 1; str += scope.count; str += '_'; // type_count_dayAndCount2 if (scope.type.Value == 'month' || scope.type.Value == 'year') { if (!scope.dayAndCount2) scope.dayAndCount2 = scope.dayAndCount2Src[0]; str += (scope.dayAndCount2.Value != null ? scope.dayAndCount2.Value.toString() : ''); } str += '_'; // type_count_dayAndCount2_days if (scope.type.Value == 'month' || scope.type.Value == 'year') { if (scope.dayAndCount2.Value != null) { if (!scope.days || scope.days < 1) scope.days = 1; } else { scope.days = null; } str += (scope.days != null ? scope.days : ''); } str += '_'; // change dates if (scope.type.Value == 'month') { scope.startDate = moment(scope.startDate).set({ 'date': 1 }); scope.endDate = moment(scope.endDate).set({ 'date': 1 }); } // change dates if (scope.type.Value == 'year' && scope.dayAndCount2Month && scope.dayAndCount2Month.Value) { scope.startDate = moment(scope.startDate).set({ 'date': 1, 'month': scope.dayAndCount2Month.Value }); scope.endDate = moment(scope.endDate).set({ 'date': 1, 'month': scope.dayAndCount2Month.Value }); } // type_count_dayAndCount2_days_weekDays if (scope.type.Value == 'week') { var numberArray = []; for (var i = 0; i < scope.weekDays.length; i++) { numberArray.push(scope.weekDays[i].Value); } str += numberArray.toString(); } // type_count_dayAndCount2_days_weekDays#extra if (!scope.extra || scope.extra == '' || scope.extra == 'no') { scope.extra = 'no'; str += '#no'; scope.endDate = moment("9999-02-01 00:00 +0000", "YYYY-MM-DD HH:mm Z"); } else { if (!isNaN(scope.extra)) // if is a number { var nr = Number(scope.extra); str += '#' + nr; } } if (scope.duration) { scope.length = scope.duration.asSeconds(); } scope.skipChangeEvent = true; ngModel.$setViewValue(str); } else { if (scope.duration) { scope.length = scope.duration.asSeconds(); scope.endDate = moment(scope.startDate).add(scope.length, 'seconds'); scope.duration = null; scope.length = null; } scope.skipChangeEvent = true; scope.clear(); ngModel.$setViewValue(str); } switch (scope.type.Value) { case "day": if (!isNaN(scope.count) && !isNaN(scope.extra) && // if is a number moment(scope.startDate).isValid()) { var nr = Number(scope.extra); scope.endDate = moment(scope.startDate).add(scope.count * nr, 'days'); } break; case "week": if (!isNaN(scope.count) && !isNaN(scope.extra) && // if is a number moment(scope.startDate).isValid()) { // [Case 1/1]: Every [2] weeks on [sun, mon, thu] // var nr = Number(scope.extra); // Step1: Move startDate to start of week scope.startDate = moment(scope.startDate).startOf('week'); // Step2: Count repetitions and compare with nr (extra) // Consider that startDate may start with (monday = 1 or sunday = 0) var cnt = 0; var cursor = scope.startDate; while (cnt < nr) { var startDOW = tempStart.isoWeekday(); for (var i = startDOW; i <= startDOW+6; i++) { if (scope.weekDays.filter(function(e) { return e.Value === i; }).length > 0) // if day of week is flagged in weekDays { cnt++; } if (cnt >= nr) break; } // Step3: Go to next *n week cursor = cursor.add(scope.count, 'weeks'); } // In case of no extra case endDate is already set to 9999-02-01 00:00 +0000 scope.endDate = cursor; } break; case "month": if (!isNaN(scope.count) && !isNaN(scope.extra) && // if is a number moment(scope.startDate).isValid()) { var nr = Number(scope.extra); scope.endDate = moment(scope.startDate).startOf('month').add(scope.count * nr + 1, 'months'); } break; case "year": if (!isNaN(scope.count) && !isNaN(scope.extra) && // if is a number moment(scope.startDate).isValid()) { var nr = Number(scope.extra); scope.endDate = moment(scope.startDate).startOf('year').add(scope.count * nr + 1, 'years'); } break; } return str; } scope.typeShow = function() { return true; } scope.typeSize = function() { if (scope.type && scope.type.Value == null) return 100; if (scope.type && scope.type.Value != null && scope.type.Value == 'none') return 100; if (scope.type && scope.type.Value != null && scope.type.Value == '') return 100; if (scope.type && scope.type.Value != null && scope.type.Value == 'month') return 30; if (scope.type && scope.type.Value != null && scope.type.Value == 'week') return 30; if (scope.type && scope.type.Value != null && scope.type.Value == 'day') return 70; return 20; } scope.countShow = function() { return (scope.type && scope.type.Value != null && scope.type.Value != '' && scope.type.Value != 'none'); } scope.countSize = function() { if (scope.type && scope.type.Value != null && scope.type.Value == 'day') return 20; return 10; } scope.dayAndCount2Show = function() { return (scope.type && scope.type.Value != null && scope.type.Value != 'day' && scope.type.Value != 'week' && scope.type.Value != '' && scope.type.Value != 'none'); } scope.dayAndCount2Size = function() { if (scope.type && scope.type.Value != null && scope.type.Value == 'month') return 40; if (scope.type && scope.type.Value != null && scope.type.Value == 'year') return 20; return 30; } scope.dayAndCount2MonthShow = function() { return (scope.type && scope.type.Value != null && scope.type.Value == 'year' && scope.type.Value != '' && scope.type.Value != 'none'); } scope.dayAndCount2MonthSize = function() { return 30; } scope.daysShow = function() { return (scope.type && scope.type.Value != null && scope.type.Value != 'day' && scope.type.Value != 'week' && scope.type.Value != '' && scope.type.Value != 'none'); } scope.daysSize = function() { return 10; } scope.weekDaysShow = function() { return (scope.type && scope.type.Value != null && scope.type.Value == 'week' && scope.type.Value != '' && scope.type.Value != 'none'); } scope.weekDaysSize = function() { if (scope.type && scope.type.Value != null && scope.type.Value == 'week') return 50; return 20; } scope.extraShow = function() { return (scope.type && scope.type.Value != null && scope.type.Value != '' && scope.type.Value != 'none'); } scope.extraSize = function() { return 10; } scope.durationShow = function() { return (scope.type && scope.type.Value != null && scope.type.Value != '' && scope.type.Value != 'none'); } scope.durationSize = function() { return 10; } } } } ]); t3_ng_app_index.directive('mdSignature', [ function() { return { require: '?ngModel', template: '' + '